from datetime import date

# 创建日期
print(date(2019, 10, 1))  # 2019-10-01

# 获得当前日期
print(date.today())  # 2025-09-22

# 得到date对象时间元祖
d = date.today()
print(d.timetuple()) # time.struct_time(tm_year=2025, tm_mon=9, tm_mday=22, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=265, tm_isdst=-1)


#  得到date对象的星期
print(d.weekday()) # 0
print(d.isocalendar()) # datetime.IsoCalendarDate(year=2025, week=39, weekday=1)
calendar = d.isocalendar().weekday
print(calendar) # 星期几 1

#  date对象的 年份，第几周，周几
print(d.isoweekday())  # 1 星期几

# 格式化
print(d.strftime('%Y年%m月%d日')) # 2025年09月22日

# date对象的替换 (统计里面，同比，环比，替换日期时间)
new_data = d.replace(year=2019,month=2, day=2)
print(new_data) # 2019-02-02